﻿#include "ZCommon.h"
#include "ZString.h"
#include <stdarg.h>
#include <wchar.h>

#define free nedfree
#define malloc nedmalloc
#define realloc nedrealloc

#ifndef WIN32
char *strupr(char *str) 
{ 
	char *ptr = str; 

	while (*ptr != '\0') { 
		if (islower(*ptr)) 
		*ptr = toupper(*ptr); 
		ptr++; 
	} 

	return str; 
}

char *strlwr(char *str) 
{ 
	char *ptr = str; 

	while (*ptr != '\0') { 
		if (isupper(*ptr)) 
		*ptr = tolower(*ptr); 
		ptr++; 
	} 

	return str; 
}

wchar_t *wcsupr(wchar_t *str) 
{ 
	wchar_t *ptr = str; 

	while (*ptr != '\0') { 
		if (islower(*ptr)) 
		*ptr = toupper(*ptr); 
		ptr++; 
	} 

	return str; 
}

wchar_t *wcslwr(wchar_t *str) 
{ 
	wchar_t *ptr = str; 

	while (*ptr != '\0') { 
		if (isupper(*ptr)) 
		*ptr = tolower(*ptr); 
		ptr++; 
	} 

	return str; 
}


#else
#define vsnprintf _vsnprintf_c
#endif




namespace ZuiLib
{
	ZString::ZString() : m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{
		m_szBuffer[0] = '\0';
		m_pstrEnd=m_pstr;
	}

	ZString::ZString(const ZChar ch) : m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{
		m_szBuffer[0] = ch;
		m_szBuffer[1] = '\0';
		m_pstrEnd=m_pstr+1;
	}

	ZString::ZString(const ZChar* lpsz, int nLen) : m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{      
		if(!lpsz){ lpsz= "";nLen=0;}
		m_szBuffer[0] = '\0';
		Assign(lpsz, nLen);
	}

	ZString::ZString(const ZString& src) : m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{
		m_szBuffer[0] = '\0';
		Assign(src.m_pstr);
	}



	ZString::~ZString()
	{
		if( m_pstr != m_szBuffer ) free(m_pstr);
	}

	int ZString::GetLength() const
	{
		return int(m_pstrEnd-m_pstr); 
	}

	ZString::operator const ZChar*() const 
	{ 
		return m_pstr; 
	}

	void ZString::Append(const ZChar* pstr)
	{
		if(!pstr) pstr="";
		int oldLength= GetLength();
		int nNewLength = oldLength + (int) strlen(pstr);

		Resize(nNewLength);
		for (int i=oldLength;i<nNewLength;++i,++pstr)
		{
			m_pstr[i]=*pstr;
		}
		m_pstrEnd=m_pstr+nNewLength;
	}


	void ZString::Append(ZChar ch)
	{
		int nNewLength = GetLength() ;
		Resize(nNewLength+1);
		m_pstr[nNewLength]=ch;
		m_pstr[nNewLength+1]='\0';
		m_pstrEnd=m_pstr+nNewLength+1;
	}


	void ZString::Assign(const ZChar* pstr, int cchMax)
	{
		if( pstr == NULL ) pstr = "";
		cchMax = (cchMax < 0 ? (int) strlen(pstr) : cchMax);

		if( cchMax > m_allocSize) {
			if( m_pstr == m_szBuffer ) m_pstr = NULL;
			m_allocSize=GetAssignSize(cchMax);
			m_pstr = static_cast<ZChar*>(realloc(m_pstr, (m_allocSize+1) * sizeof(ZChar)));
		}
		strncpy(m_pstr, pstr, cchMax);
		m_pstr[cchMax] = '\0';
		m_pstrEnd=m_pstr+cchMax;
	}

	int ZString::GetAssignSize(int size)
	{
		if(size<=MAX_LOCAL_STRING_LEN)
			return MAX_LOCAL_STRING_LEN;

		int newSize=MAX_LOCAL_STRING_LEN+1;
		while(size>newSize)
		{
			newSize*=2;
		}
		return newSize;
	}

	//重新分配大小
	void ZString::Resize(int size)
	{
		if( size > m_allocSize ) 
		{
			m_allocSize=GetAssignSize(size);
			if( m_pstr == m_szBuffer ) {
				int len=m_pstrEnd-m_pstr;

				m_pstr = static_cast<ZChar*>(malloc((m_allocSize+1) * sizeof(ZChar)));
				m_pstrEnd=m_pstr+len;

				strcpy(m_pstr, m_szBuffer);
			}
			else {
				int len=m_pstrEnd-m_pstr;
				m_pstr = static_cast<ZChar*>(realloc(m_pstr, (m_allocSize+1) * sizeof(ZChar)));
				m_pstrEnd=m_pstr+len;
			}
		}
		m_pstrEnd=m_pstr+size;
		*m_pstrEnd='\0';
	}


	bool ZString::IsEmpty() const 
	{ 
		return m_pstr[0] == '\0'; 
	}

	void ZString::Empty() 
	{ 
		if( m_pstr != m_szBuffer ) free(m_pstr);
		m_pstr = m_szBuffer;
		m_pstrEnd=m_pstr;
		m_szBuffer[0] = '\0'; 
	}

	const ZChar* ZString::GetString() const
	{
		return m_pstr;
	}

	ZChar* ZString::GetData()
	{
		return m_pstr;
	}

	ZChar ZString::GetAt(int nIndex) const
	{
		return m_pstr[nIndex];
	}

	ZChar ZString::operator[] (int nIndex) const
	{ 
		return m_pstr[nIndex];
	}   

	const ZString& ZString::operator=(const ZString& src)
	{      
		Assign(src);
		return *this;
	}

	const ZString& ZString::operator=(const ZChar* lpStr)
	{      
		if (lpStr)
		{
			Assign(lpStr);
		}
		else
		{
			Empty();
		}
		return *this;
	}


	const ZString& ZString::operator=(const ZChar ch)
	{
		Empty();
		m_szBuffer[0] = ch;
		m_szBuffer[1] = '\0';
		return *this;
	}

	ZString ZString::operator+(const ZString& src) const
	{
		ZString sTemp = *this;
		sTemp.Append(src);
		return sTemp;
	}

	ZString ZString::operator+(const ZChar* lpStr) const
	{
		if ( lpStr )
		{
			ZString sTemp = *this;
			sTemp.Append(lpStr);
			return sTemp;
		}

		return *this;
	}

	const ZString& ZString::operator+=(const ZString& src)
	{      
		Append(src);
		return *this;
	}

	const ZString& ZString::operator+=(const ZChar* lpStr)
	{      
		if ( lpStr )
		{
			Append(lpStr);
		}
		
		return *this;
	}

	const ZString& ZString::operator+=(const ZChar ch)
	{      
		Append(ch);
		return *this;
	}

	bool ZString::operator == (const ZChar* str) const { return (Compare(str) == 0); };
	bool ZString::operator != (const ZChar* str) const { return (Compare(str) != 0); };
	bool ZString::operator <= (const ZChar* str) const { return (Compare(str) <= 0); };
	bool ZString::operator <  (const ZChar* str) const { return (Compare(str) <  0); };
	bool ZString::operator >= (const ZChar* str) const { return (Compare(str) >= 0); };
	bool ZString::operator >  (const ZChar* str) const { return (Compare(str) >  0); };

	void ZString::SetAt(int nIndex, ZChar ch)
	{
		ZASSERT(nIndex>=0 && nIndex<GetLength());
		m_pstr[nIndex] = ch;
	}

	int ZString::Compare(const ZChar* lpsz) const 
	{ 
		return strcmp(m_pstr, lpsz); 
	}

	int ZString::CompareNoCase(const ZChar* lpsz) const 
	{ 
		return stricmp(m_pstr, lpsz); 
	}

	void ZString::MakeUpper() 
	{ 
		strupr(m_pstr); 
	}

	void ZString::MakeLower() 
	{ 
		strlwr(m_pstr); 
	}

	ZString ZString::Left(int iLength) const
	{
		if( iLength < 0 ) iLength = 0;
		if( iLength > GetLength() ) iLength = GetLength();
		return ZString(m_pstr, iLength);
	}

	ZString ZString::Mid(int iPos, int iLength) const
	{
		if( iLength < 0 ) iLength = GetLength() - iPos;
		if( iPos + iLength > GetLength() ) iLength = GetLength() - iPos;
		if( iLength <= 0 ) return ZString();
		return ZString(m_pstr + iPos, iLength);
	}

	ZString ZString::Right(int iLength) const
	{
		int iPos = GetLength() - iLength;
		if( iPos < 0 ) {
			iPos = 0;
			iLength = GetLength();
		}
		return ZString(m_pstr + iPos, iLength);
	}

	int ZString::Find(ZChar ch, int iPos /*= 0*/) const
	{
		ZASSERT(iPos>=0 && iPos<=GetLength());
		if( iPos != 0 && (iPos < 0 || iPos >= GetLength()) ) return -1;
		const ZChar* p = strchr(m_pstr + iPos, ch);
		if( p == NULL ) return -1;
		return (int)(p - m_pstr);
	}

	int ZString::Find(const ZChar* pstrSub, int iPos /*= 0*/) const
	{
		ZASSERT(iPos>=0 && iPos<=GetLength());
		if( iPos != 0 && (iPos < 0 || iPos > GetLength()) ) return -1;
		const ZChar* p = strstr(m_pstr + iPos, pstrSub);
		if( p == NULL ) return -1;
		return (int)(p - m_pstr);
	}

	int ZString::ReverseFind(ZChar ch) const
	{
		const ZChar* p = strrchr(m_pstr, ch);
		if( p == NULL ) return -1;
		return (int)(p - m_pstr);
	}

	int ZString::Replace(const ZChar* pstrFrom, const ZChar* pstrTo)
	{
		ZString sTemp;
		int nCount = 0;
		int iPos = Find(pstrFrom);
		if( iPos < 0 ) return 0;
		int cchFrom = (int) strlen(pstrFrom);
		int cchTo = (int) strlen(pstrTo);
		while( iPos >= 0 ) {
			sTemp = Left(iPos);
			sTemp += pstrTo;
			sTemp += Mid(iPos + cchFrom);
			Assign(sTemp);
			iPos = Find(pstrFrom, iPos + cchTo);
			nCount++;
		}
		return nCount;
	}
    
    int ZString::Format(const ZChar* pstrFormat, va_list Args)
    {
		int totalLen = (1024)*sizeof(ZChar);
		ZChar* szBuffer = (ZChar*)malloc(totalLen);
		memset(szBuffer,0,totalLen);
		int nLen = vsnprintf(szBuffer, totalLen, pstrFormat, Args);
		Assign(szBuffer);
		free(szBuffer);
		return nLen;
    }

    int ZString::Format(const ZChar* pstrFormat, ...)
    {
        int nRet;
        va_list Args;

        va_start(Args, pstrFormat);
        nRet = Format(pstrFormat, Args);
        va_end(Args);

        return nRet;

    }

	int ZString::SmallFormat(const ZChar* pstrFormat, ...)
	{
		ZString sFormat = pstrFormat;
		ZChar szBuffer[64] = { 0 };
		va_list argList;
		va_start(argList, pstrFormat);
		int iRet = vsnprintf(szBuffer, sizeof(szBuffer), sFormat, argList);
		va_end(argList);
		Assign(szBuffer);
		return iRet;
	}

	bool ZString::Insert(int pos,const ZChar* pstr,int len2)
	{
		if (pos>GetLength() || pos<0 || pstr==NULL)
		{
			return false;
		}
		int len=GetLength();
		int strLen =len2<0?(int)strlen(pstr):len2;
		Resize(strLen+len);

		for (int i=len;i>=pos;--i)
		{
			m_pstr[i+strLen]=m_pstr[i];
		}

		for (int i=0;i<strLen;++i)
		{
			m_pstr[pos+i]=pstr[i];
		}
		m_pstrEnd=m_pstr+strLen+len;
		return true;
	}


	bool ZString::Insert(int pos,ZChar text)
	{
		if (pos>GetLength() || pos<0 )
		{
			return false;
		}
		int len=GetLength();
		Resize(len+1);

		for (int i=len;i>=pos;--i)
		{
			m_pstr[i+1]=m_pstr[i];
		}
		m_pstr[pos]=text;
		m_pstrEnd=m_pstr+len+1;
		return true;
	}


	bool ZString::Remove(int pos,int len)
	{
		int left=0,right=0;
		if (len>0)
		{
			left=pos;
			right=pos+len;
		}
		else
		{
			left=pos+len;
			right=pos;
		}
		if (left<0)
		{
			return false;
		}

		int textlen=GetLength();
		if (right>textlen)
		{
			return false;
		}

		for (int pos=right;pos<=textlen;++pos)
		{
			m_pstr[left+pos-right]=m_pstr[pos];
		}

		m_pstrEnd=m_pstr+strlen(m_pstr);
		return true;
	}

	//////////////////////////////////////////////////////////////////////////////////////////////
	ZWString::ZWString() :  m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{
		m_szBuffer[0] = '\0';
		m_pstrEnd=m_pstr;
	}

	ZWString::ZWString(const ZWChar ch) : m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{
		m_szBuffer[0] = ch;
		m_szBuffer[1] = '\0';
		m_pstrEnd=m_pstr+1;
	}

	ZWString::ZWString(const ZWChar* lpsz, int nLen) : m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{      
		if(!lpsz){ lpsz= L"";nLen=0;}
		m_szBuffer[0] = L'\0';
		Assign(lpsz, nLen);
	}

	ZWString::ZWString(const ZWString& src) : m_pstr(m_szBuffer),m_allocSize(MAX_LOCAL_STRING_LEN)
	{
		m_szBuffer[0] = '\0';
		Assign(src.m_pstr);
	}

	ZWString::~ZWString()
	{
		if( m_pstr != m_szBuffer ) free(m_pstr);
	}

	int ZWString::GetLength() const
	{
		return (int)(m_pstrEnd-m_pstr);
	}

	int ZWString::GetAssignSize(int size)
	{
		if(size<=MAX_LOCAL_STRING_LEN)
			return MAX_LOCAL_STRING_LEN;

		int newSize=MAX_LOCAL_STRING_LEN+1;
		while(size>newSize)
		{
			newSize*=2;
		}
		return newSize;
	}

	ZWString::operator const ZWChar*() const 
	{ 
		return m_pstr; 
	}

	void ZWString::Append(const ZWChar* pstr)
	{
		if(!pstr) pstr=L"";
		int oldLength= GetLength();
		int nNewLength = oldLength + (int) wcslen(pstr);

		Resize(nNewLength);
		for (int i=oldLength;i<nNewLength;++i,++pstr)
		{
			m_pstr[i]=*pstr;
		}
		m_pstrEnd=m_pstr+nNewLength;
	}

	void ZWString::Append(ZWChar ch)
	{
		int nNewLength = GetLength() ;
		Resize(nNewLength+1);
		m_pstr[nNewLength]=ch;
		m_pstr[nNewLength+1]='\0';
		m_pstrEnd=m_pstr+nNewLength+1;
	}

	void ZWString::Assign(const ZWChar* pstr, int cchMax)
	{
		if( pstr == NULL ) pstr = L"";
		cchMax = (cchMax < 0 ? (int) wcslen(pstr) : cchMax);

		if( cchMax > m_allocSize) {
			if( m_pstr == m_szBuffer ) 
				m_pstr = NULL;
			m_allocSize=GetAssignSize(cchMax);
			m_pstr = static_cast<ZWChar*>(realloc(m_pstr, (m_allocSize+1) * sizeof(ZWChar)));
		}
		wcsncpy(m_pstr, pstr, cchMax);
		m_pstr[cchMax] = '\0';
		m_pstrEnd=m_pstr+cchMax;
	}


	void ZWString::Resize(int size)
	{
		if( size > m_allocSize ) 
		{
			m_allocSize=GetAssignSize(size);
			if( m_pstr == m_szBuffer ) {
				int len=m_pstrEnd-m_pstr;

				m_pstr = static_cast<ZWChar*>(malloc((m_allocSize+1) * sizeof(ZWChar)));
				m_pstrEnd=m_pstr+len;

				wcscpy(m_pstr, m_szBuffer);
			}
			else {
				int len=m_pstrEnd-m_pstr;
				m_pstr = static_cast<ZWChar*>(realloc(m_pstr, (m_allocSize+1) * sizeof(ZWChar)));
				m_pstrEnd=m_pstr+len;
			}
		}
		m_pstrEnd=m_pstr+size;
		*m_pstrEnd='\0';
	}

	bool ZWString::IsEmpty() const 
	{ 
		return m_pstr[0] == '\0'; 
	}

	void ZWString::Empty() 
	{ 
		if( m_pstr != m_szBuffer ) free(m_pstr);
		m_pstr = m_szBuffer;
		m_pstrEnd=m_pstr;
		m_szBuffer[0] = '\0'; 
	}

	const ZWChar* ZWString::GetString() const
	{
		return m_pstr;
	}

	ZWChar* ZWString::GetData()
	{
		return m_pstr;
	}

	ZWChar ZWString::GetAt(int nIndex) const
	{
		return m_pstr[nIndex];
	}

	ZWChar ZWString::operator[] (int nIndex) const
	{ 
		return m_pstr[nIndex];
	}   

	const ZWString& ZWString::operator=(const ZWString& src)
	{      
		Assign(src);
		return *this;
	}

	const ZWString& ZWString::operator=(const ZWChar* lpStr)
	{      
		if (lpStr)
		{
			Assign(lpStr);
		}
		else
		{
			Empty();
		}
		return *this;
	}


	const ZWString& ZWString::operator=(const ZWChar ch)
	{
		Empty();
		m_szBuffer[0] = ch;
		m_szBuffer[1] = '\0';
		return *this;
	}

	ZWString ZWString::operator+(const ZWString& src) const
	{
		ZWString sTemp = *this;
		sTemp.Append(src);
		return sTemp;
	}

	ZWString ZWString::operator+(const ZWChar* lpStr) const
	{
		if ( lpStr )
		{
			ZWString sTemp = *this;
			sTemp.Append(lpStr);
			return sTemp;
		}

		return *this;
	}

	const ZWString& ZWString::operator+=(const ZWString& src)
	{
		Append(src);
		return *this;
	}

	const ZWString& ZWString::operator+=(const ZWChar* lpStr)
	{      
		if ( lpStr )
		{
			Append(lpStr);
		}
		
		return *this;
	}

	const ZWString& ZWString::operator+=(const ZWChar ch)
	{      
		Append(ch);
		return *this;
	}

	bool ZWString::operator == (const ZWChar* str) const { return (Compare(str) == 0); };
	bool ZWString::operator != (const ZWChar* str) const { return (Compare(str) != 0); };
	bool ZWString::operator <= (const ZWChar* str) const { return (Compare(str) <= 0); };
	bool ZWString::operator <  (const ZWChar* str) const { return (Compare(str) <  0); };
	bool ZWString::operator >= (const ZWChar* str) const { return (Compare(str) >= 0); };
	bool ZWString::operator >  (const ZWChar* str) const { return (Compare(str) >  0); };

	void ZWString::SetAt(int nIndex, ZWChar ch)
	{
		ZASSERT(nIndex>=0 && nIndex<GetLength());
		m_pstr[nIndex] = ch;
	}

	int ZWString::Compare(const ZWChar* lpsz) const 
	{
		return wcscmp(m_pstr, lpsz); 
	}

	int ZWString::CompareNoCase(const ZWChar* lpsz) const 
	{ 
		return wcsicmp(m_pstr, lpsz); 
	}

	void ZWString::MakeUpper() 
	{ 
		wcsupr(m_pstr); 
	}

	void ZWString::MakeLower() 
	{ 
		wcslwr(m_pstr); 
	}

	ZWString ZWString::Left(int iLength) const
	{
		if( iLength < 0 ) iLength = 0;
		if( iLength > GetLength() ) iLength = GetLength();
		return ZWString(m_pstr, iLength);
	}

	ZWString ZWString::Mid(int iPos, int iLength) const
	{
		if( iLength < 0 ) iLength = GetLength() - iPos;
		if( iPos + iLength > GetLength() ) iLength = GetLength() - iPos;
		if( iLength <= 0 ) return ZWString();
		return ZWString(m_pstr + iPos, iLength);
	}

	ZWString ZWString::Right(int iLength) const
	{
		int iPos = GetLength() - iLength;
		if( iPos < 0 ) {
			iPos = 0;
			iLength = GetLength();
		}
		return ZWString(m_pstr + iPos, iLength);
	}

	int ZWString::Find(ZWChar ch, int iPos /*= 0*/) const
	{
		ZASSERT(iPos>=0 && iPos<=GetLength());
		if( iPos != 0 && (iPos < 0 || iPos >= GetLength()) ) return -1;
		const ZWChar* p = wcschr(m_pstr + iPos, ch);
		if( p == NULL ) return -1;
		return (int)(p - m_pstr);
	}

	int ZWString::Find(const ZWChar* pstrSub, int iPos /*= 0*/) const
	{
		ZASSERT(iPos>=0 && iPos<=GetLength());
		if( iPos != 0 && (iPos < 0 || iPos > GetLength()) ) return -1;
		const ZWChar* p = wcsstr(m_pstr + iPos, pstrSub);
		if( p == NULL ) return -1;
		return (int)(p - m_pstr);
	}

	int ZWString::ReverseFind(ZWChar ch) const
	{
		const ZWChar* p = wcsrchr(m_pstr, ch);
		if( p == NULL ) return -1;
		return (int)(p - m_pstr);
	}

	int ZWString::Replace(const ZWChar* pstrFrom, const ZWChar* pstrTo)
	{
		ZWString sTemp;
		int nCount = 0;
		int iPos = Find(pstrFrom);
		if( iPos < 0 ) return 0;
		int cchFrom = (int) wcslen(pstrFrom);
		int cchTo = (int) wcslen(pstrTo);
		while( iPos >= 0 ) {
			sTemp = Left(iPos);
			sTemp += pstrTo;
			sTemp += Mid(iPos + cchFrom);
			Assign(sTemp);
			iPos = Find(pstrFrom, iPos + cchTo);
			nCount++;
		}
		return nCount;
	}


	bool ZWString::Insert(int pos,const ZWChar* pstr,int len2)
	{
		if (pos>GetLength() || pos<0 || pstr==NULL)
		{
			return false;
		}
		int len=GetLength();
		int strlen =len2<0?(int)wcslen(pstr):len2;
		Resize(strlen+len);

		for (int i=len;i>=pos;--i)
		{
			m_pstr[i+strlen]=m_pstr[i];
		}

		for (int i=0;i<strlen;++i)
		{
			m_pstr[pos+i]=pstr[i];
		}
		m_pstrEnd=m_pstr+strlen+len;
		return true;
	}


	bool ZWString::Insert(int pos,ZWChar text)
	{
		if (pos>GetLength() || pos<0 )
		{
			return false;
		}
		int len=GetLength();
		Resize(len+1);

		for (int i=len;i>=pos;--i)
		{
			m_pstr[i+1]=m_pstr[i];
		}
		m_pstr[pos]=text;
		m_pstrEnd=m_pstr+len+1;
		return true;
	}

	bool ZWString::Remove(int pos,int len)
	{
		int left=0,right=0;
		if (len>0)
		{
			left=pos;
			right=pos+len;
		}
		else
		{
			left=pos+len;
			right=pos;
		}
		if (left<0)
		{
			return false;
		}

		int textlen=GetLength();
		if (right>textlen)
		{
			return false;
		}

		for (int pos=right;pos<=textlen;++pos)
		{
			m_pstr[left+pos-right]=m_pstr[pos];
		}

		m_pstrEnd=m_pstr+wcslen(m_pstr);

		return true;
	}
    
	void Utf8ToUtf16(const ZString* utf8,ZWString* utf16)
	{
		int utf8Len=utf8->GetLength();
		int count=ZTextCountCharsFromUtf8(utf8->GetString(),utf8->GetString()+utf8Len);
		utf16->Resize(count);//包含了结束符
		ZTextStrFromUtf8(utf16->GetData(),count+1,utf8->GetString(),utf8->GetString()+utf8Len,NULL);
	}


	void Utf16ToUtf8(const ZWString* utf16,ZString* utf8)
	{
		int utf16Len=utf16->GetLength();
		int count=ZTextCountUtf8BytesFromStr(utf16->GetString(),utf16->GetString()+utf16Len);
		utf8->Resize(count);//包含了结束符
		ZTextStrToUtf8(utf8->GetData(),count+1,utf16->GetString(),utf16->GetString()+utf16Len);
	}

}//namespace
